package cn.enjoy.tool.base;

import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author K
 */
public class FunctionInterface2 {

    public static void main(String[] args) {
        System.out.println(supplier());
        consumer("k");
        biConsumer("a", "b");
    }


    /**
     * 1入参 0结果
     */
    public static void consumer(Object o) {
        Consumer<Object> consumer = new Consumer<Object>() {
            @Override
            public void accept(Object o) {
                System.out.println("Consumer " + o);
            }
        };
        // lambda简化
        // Consumer<Object> consumer = o1 -> System.out.println("consumer " + o1);
        consumer.accept(o);
    }

    /**
     * 0入参 1结果
     */
    public static Object supplier() {
        Supplier<Object> supplier = new Supplier<Object>() {
            @Override
            public Object get() {
                return 1;
            }
        };
        // lambda简化
        // Supplier<Object> supplier = () -> 1;
        return supplier.get();
    }

    /**
     * 1入参 1结果
     */
    public static Object function(Object o) {
        Function<Object, Object> function = new Function<Object, Object>() {
            @Override
            public Object apply(Object o) {
                return o + "hhh";
            }
        };
        // lambda简化
        // Function<Object, Object> function = o1 -> o1 + "hhh";
        return function.apply(o);
    }

    // ########################### Bi开头都是2个入参  ####################################

    /**
     * 2入参 0结果
     */
    public static void biConsumer(Object o, Object o2) {
        BiConsumer<Object, Object> consumer = new BiConsumer<Object, Object>() {
            @Override
            public void accept(Object o, Object o2) {
                System.out.println("BiConsumer " + o + " " + o2);
            }
        };
        consumer.accept(o, o2);
    }

}